package com.woniuxy.redis01.controller;

import cn.hutool.extra.mail.MailUtil;
import com.woniuxy.redis01.entity.Student;
import com.woniuxy.redis01.service.SomeService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author 作者
 * @create 2025-06-24 9:46
 */
@RestController
@RequestMapping("/apitest")
public class MyController {

    @Autowired
    SomeService someService;

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Value("${server.port}")
    int port;

    @RequestMapping("/getdata")
    public String getData(){
        String date = someService.getDate();
//        System.out.println("data="+date);
        return port+"---"+date;
    }
    @RequestMapping("/incr1")
    public String incr1(){
        someService.incr1();
        return "incr1";
    }
    @RequestMapping("/incr2")
    public String incr2(){
        someService.incr2();
        return "incr2";
    }
    @RequestMapping("/email")
    public String email(){
        String code = UUID.randomUUID().toString().substring(0, 4);
        //MQ
//        new Thread(()->{
//            MailUtil.send("chinasofti_lbs@163.com", "找回密码", "验证码:"+code, false);
//        }).start();

        rabbitTemplate.convertAndSend("exchangetopic", "email",new Student(1,"张三", 18));

        return "email ok";
    }

    @RequestMapping("/init")
    public String init(){
        someService.init();
        return "init-ok";
    }
    @RequestMapping("/second")
    public String second(){
        someService.second();
        return "second-ok";
    }
}
